﻿#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"

void intboard(char board[ROWS][COLS], int rows, int cols, char set)
{
	for (int i = 0; i < ROWS; i++)
	{
		for (int j = 0; j < COLS; j++)
		{
			board[i][j] = set;
	    }
    }
}

void displayboard(char board[ROWS][COLS], int row, int col)
{
	printf("--------扫雷--------\n");
	for (int i = 0; i <=COL; i++)
	{
		printf("%d ", i);
    }
	     printf("\n");
	for (int i = 1; i <= ROW; i++)
	{
		printf("%d ", i);
		for (int j = 1; j <= COL; j++)
		{
			printf("%c ",board[i][j]);
		}
		printf("\n");
	}



}
void setboard(char board[ROWS][COLS], int row, int col)
{//布置10个雷
 //⽣成随机的坐标，布置雷
	int count = EASY_COUNT;
	while (count)
	{
		int x = rand()% ROW + 1;
		int y = rand()% COL + 1;
		if (board[x][y]=='0')
		{
			board[x][y] = '1';
			count--;
		}
		
	}



}
int getminecount(char mine[ROWS][COLS], int x, int y)
{
	return (mine[x - 1][y] + mine[x - 1][y - 1] + mine[x][y - 1] + mine[x + 1][y - 1] + mine[x+1][y]+
		mine[x + 1][y + 1] + mine[x][y + 1] + mine[x - 1][y + 1] - 8 * '0');


}
void findmine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
	int x, y;
	int win = 0;
	while (win<ROW * COL - EASY_COUNT)
	{
		printf("请输入要查找的坐标：>");
		scanf("%d %d", &x, &y);
		if (x >= 1 && x <= ROW && y <= COL && y >= 1)
		{
			if (mine[x][y] == '1')
			{
				printf("很遗憾，你被炸死了\n");
				displayboard(mine, ROW, COL);
				break;
		    }
			else
			{
				int count = getminecount(mine, x,y);
				show[x][y] = count + '0';
				displayboard(show, ROW, COL);
				win++;
			}


		}
		else {
			printf("坐标非法，重输入\n");
		}
		if (win == ROW * COL - EASY_COUNT)
		{
			printf("恭喜你，胜利\n");
			displayboard(mine, ROW, COL);
		}

	}




}